﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;
using MyDMS.DAL;

namespace MyDMS_ExtJS.Admin
{
    public partial class UserRole : System.Web.UI.Page
    {
        private MyDMSEntity _myDmsEntity = new MyDMSEntity();
        protected void Page_Load(object sender, EventArgs e)
        {

            btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("至少选择一项！");
            btnNew.OnClientClick = Window1.GetShowReference("UserRoleEdit.aspx", "新增");

            BindGrid();
        }
        private void BindGrid()
        {

            Grid1.DataSource = _myDmsEntity.UserRole.ToList();
            Grid1.DataBind();
        }
        protected string GetEditUrl(object id, object name)
        {
            return "javascript:" + Window1.GetShowReference("UserRoleEdit.aspx?id=" + id, "编辑 - " + name);
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            foreach (int row in Grid1.SelectedRowIndexArray)
            {
                int index = Convert.ToInt32(Grid1.DataKeys[row][0].ToString());
                var sf = _myDmsEntity.UserRole.FirstOrDefault(d => d.Role_Code == index);
                if (sf != null)
                {
                    _myDmsEntity.UserRole.DeleteObject(sf);
                }
                _myDmsEntity.SaveChanges();
            }
            Alert.ShowInTop("你删除了" + Grid1.SelectedRowIndexArray.Count() + "项");
            BindGrid();
        }
    }
}